package com.example.data_pass_back;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    TextView mytextview;
    final int result = 1;
    final int request = 1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mytextview = (TextView)findViewById(R.id.textviewshow);
        Log.v("life","MainActivity onCreate");
//        Intent intent=getIntent();
//        String string = intent.getStringExtra("userID");
//        mytextview.setText("用户ID为"+string);
    }
    //主窗口跳转到子窗口
    public void clickChoice(View view){
        Log.v("life","MainActivity  按钮被点击");
        Intent intent = new Intent(this,ChildActivity.class);
        startActivityForResult(intent,request); //1表示点击按钮这一动作
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        Log.v("life","MainActivity onActivityResult");
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==request){
            if(resultCode==result){
                String string = data.getStringExtra("userID");
                String password = data.getStringExtra("userPwd");
                mytextview.setText("用户ID为:"+string +"\n密码为:"+password);
            }
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.v("life","MainActivity onStart");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.v("life","MainActivity onResume");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.v("life","MainActivity onPause");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.v("life","MainActivity onStop");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.v("life","MainActivity onDestroy");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.v("life","MainActivity onRestart");
    }
}
